﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;

namespace logicunivesityinventorystore.Department
{
    public partial class ViewHistory : System.Web.UI.Page
    {
        static DateTime fromDate;
        static DateTime toDate;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblHistory.Visible = false;
                lbDetails.Visible = false;
                lbDuration.Visible = false;
            }
        }

         protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {
          
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            gvDetails.DataSource = null;
            gvDetails.DataBind();
            RequisitionFacade requsition = new RequisitionFacade();
            fromDate =Convert.ToDateTime(txtFrom.Text);
             toDate = Convert.ToDateTime(txtTo.Text);
             lblFromDate.Text = txtFrom.Text;
             lblToDate.Text = txtTo.Text;
           
            string status = ddlStatus.SelectedItem.Text;

            string employeeID = User.Identity.Name;
            gvHistory.DataSource = requsition.FindHistory(employeeID, fromDate, toDate, status);
                gvHistory.DataBind();
                if (gvHistory.Rows.Count == 0)
                {
                    lbVisible(false);
                    ScriptManager.RegisterStartupScript(this,
     this.GetType(),
     "AlertScript",
     "alert('There is no history!');",
     true);
                  
                }
                else
                {
                    lblHistory.Visible = true;
                    lbDuration.Visible = true;
                    lblFromDate.Visible = true;
                    lblToDate.Visible = true;
                }
            
       
           
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
               lbDetails.Visible = true;
                RequisitionFacade requisition = new RequisitionFacade();
               string formID= e.CommandArgument.ToString();
               gvDetails.DataSource = requisition.getRequsitionDetails(formID);
               gvDetails.DataBind();
               if (gvDetails.Rows.Count == 0)
               {
                   ScriptManager.RegisterStartupScript(this,
    this.GetType(),
    "AlertScript",
    "alert('There is no detail for this requisition!');",
    true);
 
               }
            }
        }

        protected void lbVisible(bool status)
        {
            lblHistory.Visible = status;
            lbDetails.Visible = status;
            lbDuration.Visible = status;
            lblFromDate.Visible = status;
            lblToDate.Visible = status;
        }
      
    }
}